﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    //定义类
    public class DB
    {
        public int? num;
        public bool? flag = true;
        //返回可空类型int
        public int? GetRecord_int()
        {
            return num;
        }
        //返回可空类型bool
        public bool? GetRecord_bool()
        {
            return flag;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Nullable<int> x;//等价于int? x;
        x = null;
        DB db = new DB();
        //定义可空类型int
        int? i = db.GetRecord_int();
        if (i.HasValue)//判断i是否有值
        {
            Response.Write("i的值为：" + i.ToString());
        }
        else
        {
            Response.Write("i为空值！");
        }
        //定义可空类型bool
        bool? b = db.GetRecord_bool();
        if (b.HasValue)//判断b是否有值
        {
            Response.Write("<br/>b的值为：" + b.ToString());
        }
        else
        {
            Response.Write("<br/>b为空值！");
        }

    }
}
